import java.util.Scanner;
// 洛谷   P8598 [蓝桥杯 2013 省 AB] 错误票据
public class test3_2 {
    //数组实现
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        scan.nextLine();
        int[] arr = new int[10000];
        //输入数据
        for (int i = 0; i < n; i++) {
            String str = scan.nextLine();
            String[] s = str.split(" ");
            for (int j = 0; j < s.length; j++) {
                arr[Integer.parseInt(s[j])]++;
            }
        }
        //a是重复，b是断号
        int a = -1,b = -1;
        //判断开关
        boolean flaga = false,flagb = false;
        for(int i = 0;i<arr.length;i++){
            if(arr[i]>1 && !flaga){
                a = i;
                flaga = true;
            }
            if(arr[i+1]!=0 && arr[i]==0 &&arr[i-1]!=0 && !flagb){
                b = i;
                flagb = true;
            }
            if(flaga && flagb){
                break;
            }
        }
        System.out.println(b+" "+a);
    }
}
